package com.ebao.po.qa;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.ebao.constants.UserType;

/**
 * @desc 回答
 * @author snow
 * @date 2012-7-6
 */
@Entity
@Table(name = "T_Answer")
public class TAnswer implements Serializable {

	private static final long serialVersionUID = -6598762948542548381L;
	
	private Long id;
	private TQuestion question;		// 回答的问题
	private UserType userType;		// 用户类型user/doctor
	private String referId;			// 用户Id
	private String answer;			// 回答的内容
	private String answerDate;		// 回答的时间
	private Set<TVoteAnswer> voters = new HashSet<TVoteAnswer>();	// 投票
	private List<TComment> comments = new ArrayList<TComment>();	// 对回答进行评价（类似追问），多个都属同级
	
	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(optional = false, targetEntity = TQuestion.class)
	@JoinColumn(name = "question_id")
	public TQuestion getQuestion() {
		return question;
	}

	public void setQuestion(TQuestion question) {
		this.question = question;
	}

	public UserType getUserType() {
		return userType;
	}

	public void setUserType(UserType userType) {
		this.userType = userType;
	}

	public String getReferId() {
		return referId;
	}

	public void setReferId(String referId) {
		this.referId = referId;
	}

	public String getAnswer() {
		return answer;
	}

	public void setAnswer(String answer) {
		this.answer = answer;
	}

	@Column(length = 19)
	public String getAnswerDate() {
		return answerDate;
	}

	public void setAnswerDate(String answerDate) {
		this.answerDate = answerDate;
	}

	@OneToMany(cascade = {CascadeType.ALL}, mappedBy = "answer", targetEntity = TVoteAnswer.class)
	public Set<TVoteAnswer> getVoters() {
		return voters;
	}

	public void setVoters(Set<TVoteAnswer> voters) {
		this.voters = voters;
	}

	@OneToMany(cascade = {CascadeType.ALL}, mappedBy = "answer", targetEntity = TComment.class)
	public List<TComment> getComments() {
		return comments;
	}

	public void setComments(List<TComment> comments) {
		this.comments = comments;
	}
	
}
